<?
 class site extends DM{
//
//
// 
// 
// 
// VERSION: 
// AUTHOR: bugz
// DATE: 24.12.2006
// 


// VARIABLE DECLARATION
	var $id_site = "";
	var $id_company = "";
	var $txt_name = "";
	var $txt_url = "";
	var $bol_active = "";

	var $debugging=false;

	var $lista = "";


// METHOD DECLARATION

//DEBUG METHOD
	function debug($result,$operation=""){
		if ($result){
			if ($this->debugging){
				echo "<div style='font-size:10px;font-family:arial,sans;color:#FFFFFF;background-color:#008800'>OK: ";
				echo strtoupper($this->db_type)."($operation) - [No errors computed] ";
				echo "</div>";
			}
			return true;
		}else{
			if ($this->debugging){
				echo "<div style='font-family:arial,sans;color:#FFFFFF;background-color:#ff0000;font-size:10px;'>ERROR: ";
				echo strtoupper($this->db_type)."($operation) - [".$this->db->errDesc."] ".$this->db->errDesc;
				echo "</div>";
			}
			return false;
		}
		
	}

//CONSTRUCTOR METHOD
	function site($company=""){
		//LOAD THE DATABSE CLASS
		$this->loadClass('database','database');

		//INITIALIZE THE VARIABLES
		$this->id_site = "";
		$this->id_company = $company;
		$this->txt_name = "";
		$this->txt_url = "";
		$this->bol_active = "";
		$this->lista = array();

	}

//GET METHODS
//
//
//
	function getList(){

		//SQL STRING
		$sql="SELECT id_site FROM trk_site WHERE id_company='".$this->id_company."'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->fetch($sql)){
				$this->lista=$db->resultArray;
				return $this->debug(true,'get_list');
			}else{
				$this->errorReport("Error in the select",$sql);
				return $this->debug(false,"get_List - $sql");
			}
		}else{
			$this->errorReport("Could not conncet to the database",$db);
			return $this->debug(false,'get_list');
		}
	}

	function getById(){
		if ($this->id_site!=""){
			$sql = "select * from trk_site where id_site='$this->id_site'";
			$db= new database();
			$db->debugging=$this->debugging;
			if ($db->connect()){
				if ($db->fetch($sql)){
					if (count($db->resultArray)==1){
						$this->id_site = $db->resultArray[0]["id_site"];
						$this->id_company = $db->resultArray[0]["id_company"];
						$this->txt_name = $db->resultArray[0]["txt_name"];
						$this->txt_url = $db->resultArray[0]["txt_url"];
						$this->bol_active = $db->resultArray[0]["bol_active"];
						return true;
					}else{
						$this->errorReport("Error too many results.",$sql);
						return false;
					}
				}else{
					$this->errorReport("Error in the select",$sql);
					return false;
				}
			}else{
				$this->errorReport("Could not conncet to the database",$db);
				return false;
			}
		}
	}
		function save(){
			if ($this->id_site==""){
				//insert
				$sql = "";
				$sql .= "INSERT INTO trk_site(";
				$sql .= " id_site";
				$sql .= ", id_company";
				$sql .= ", txt_name";
				$sql .= ", txt_url";
				$sql .= ", bol_active";
				$sql .= ") VALUES (";
				$sql .= " ''";
				$sql .= ", '$this->id_company'";
				$sql .= ", '$this->txt_name'";
				$sql .= ", '$this->txt_url'";
				$sql .= ", '$this->bol_active'";
				$sql .= ")";
			}else{
				//update
				$sql = "";
				$sql .= "UPDATE trk_site SET";
				$sql .= " id_company";
				$sql .= " = '$this->id_company'";
				$sql .= ", txt_name";
				$sql .= " = '$this->txt_name'";
				$sql .= ", txt_url";
				$sql .= " = '$this->txt_url'";
				$sql .= ", bol_active";
				$sql .= " = '$this->bol_active'";
				$sql .= " where ";
				$sql .= " id_site = '".$this->id_site."'";
			}
			$db= new database();
			$db->debugging=$this->debugging;
			if ($db->connect()){
				if ($db->execute($sql)){
					return true;
				}else{
					$this->errorReport("Error in the select",$sql);
					return false;
				}
			}else{
				$this->errorReport("Could not conncet to the database",$db);
				return false;
			}
	}
	function delete(){
		$sql="DELETE FROM trk_site WHERE id_site='$this->id_site'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->execute($sql)){
				return true;
			}else{
				$this->errorReport("Error in the SQL:<BR>",$sql);
				return false;
			}
		}else{
			$this->errorReport("Error in the Connect");
			return false;
		}
	}


}
?>
